import { GLOBAL_STORE } from "../modulesName";
import { defineStore } from "pinia";
import { zhCN, dateZhCN } from "naive-ui";
import { IGlobalState } from "@/types/store/global.store";
import { getLanguage, setLocale } from "@/lang";
import { LANG_VALUE } from "@/constants/language";

export const useGlobalStore = defineStore({
  id: GLOBAL_STORE,
  state: (): IGlobalState => {
    return {
      theme: "light",
      isCollapse: false,
      language: getLanguage(),
    };
  },
  getters: {
    locale(state) {
      switch (state.language) {
        case LANG_VALUE.En:
          return null;
        case LANG_VALUE.Zh:
          return zhCN;
        default:
          break;
      }
    },
    dateLocale(state) {
      switch (state.language) {
        case LANG_VALUE.En:
          return null;
        case LANG_VALUE.Zh:
          return dateZhCN;
        default:
          break;
      }
    },
  },
  actions: {
    setLanguage(language: LANG_VALUE) {
      this.language = language;
      setLocale(language);
    },
    toggleSideBar(isCollapse: boolean) {
      this.isCollapse = isCollapse;
    },
  },
});
